package lg.minecraft.plugin.pokemonmenu.command;

import com.cobblemon.mod.common.pokemon.Pokemon;
import lg.minecraft.plugin.library.command.CommandContext;
import lg.minecraft.plugin.library.command.CommandType;
import lg.minecraft.plugin.library.command.SubCommand;
import lg.minecraft.plugin.pokemonmenu.LGPokemonMenu;
import lg.minecraft.plugin.pokemonmenu.PokemonPlayer;
import lg.minecraft.plugin.pokemonmenu.gui.ViewPCInventor;
import lg.minecraft.plugin.pokemonmenu.gui.ViewPartyInventor;
import lg.minecraft.plugin.pokemonmenu.gui.ViewPokemonInventory;
import lg.minecraft.plugin.pokemonmenu.manager.DisplayPokemonManger;
import lg.minecraft.plugin.pokemonmenu.manager.PokemonPlayerManger;
import org.bukkit.entity.Player;

/**
 * @author white
 * @version 1.0
 */
public class SubViewCommand extends SubCommand {

    public SubViewCommand() {
        super("view", "v");
    }

    @Override
    public String getPermission() {
        return "LGPokemonMenu.command.view";
    }

    @Override
    public CommandType getCommandType() {
        return CommandType.PLAYER;
    }

    @Override
    public String getDescription() {
        return "查看展示信息";
    }

    @Override
    public void onCommand(CommandContext context) {
        Player player = context.getPlayer();
        if (context.getArgLength() == 0) return;
        String arg = context.getArg(0);
        long time = Long.parseLong(arg);
        Pokemon[] pokemon_array = DisplayPokemonManger.INSTANCE.get(time);
        PokemonPlayer pokemonPlayer = PokemonPlayerManger.INSTANCE.getPokemonPlayer(player);

        if (pokemon_array == null) {
            player.sendMessage(LGPokemonMenu.getMessage().getDisplayedPokemonExpired());
            return;
        }

        if (pokemon_array.length == 1) {
             pokemonPlayer.setPreviousInventory(null);
            new ViewPokemonInventory(pokemon_array[0]).openInventory(player);
        } else if (pokemon_array.length <= 6) {
            new ViewPartyInventor(pokemon_array).openInventory(player);
        } else if (pokemon_array.length <= 36) {
             new ViewPCInventor(pokemon_array).openInventory(player);
        }
    }

}
